﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using LyncServerExtension.PluginModel;

namespace LyncServerExtension.Plugin.WebPage
{
    /// <summary>
    /// Class which implements a web result builder.
    /// </summary>
    public sealed class WebPageResultBuilder : ILyncResultBuilderPlugin
    {
        /// <summary>
        /// Gets the plugin id.
        /// </summary>
        public string Id
        {
            get { return "WebPage"; }
        }

        /// <summary>
        /// Gets the plugin version.
        /// </summary>
        public string Version
        {
            get { return "1.1"; }
        }

        /// <summary>
        /// Gets or sets the culture.
        /// </summary>
        /// <value>
        /// The culture to use to internationalize results of this builder.
        /// </value>
        public CultureInfo Culture { get; set; }

        /// <summary>
        /// Called when [load].
        /// </summary>
        /// <param name="context">The context.</param>
        public void OnLoad(IPluginContext context)
        {
        }

        /// <summary>
        /// Called when [unload].
        /// </summary>
        public void OnUnload()
        {
        }

        /// <summary>
        /// Sets the authorized owners.
        /// </summary>
        /// <param name="users">The users.</param>
        /// <returns>
        /// A result for the operation.
        /// </returns>
        public ILyncResult SetAuthorizedOwners(IEnumerable<LyncUser> users)
        {
            return new UserListPage(users);
        }

        /// <summary>
        /// Sets the authorized delegates.
        /// </summary>
        /// <param name="ownerSip">The owner sip.</param>
        /// <param name="users">The users.</param>
        /// <returns>
        /// A result for the operation.
        /// </returns>
        public ILyncResult SetAuthorizedDelegates(string ownerSip, IEnumerable<LyncUser> users)
        {
            return new UserListPage(users);
        }

        /// <summary>
        /// Sets the delegates.
        /// </summary>
        /// <param name="ownerSip">The owner sip.</param>
        /// <param name="users">The users.</param>
        /// <returns>
        /// A result for the operation.
        /// </returns>
        public ILyncResult SetDelegates(string ownerSip, IEnumerable<LyncUser> users)
        {
            return new UserListPage(users);
        }

        /// <summary>
        /// Sets the call forwarding delegation.
        /// </summary>
        /// <param name="param">The param.</param>
        /// <param name="state">A non used value which can be used by plugins for customisation.
        /// Can be used by a plugin to save the current enabled/disabled state for example.</param>
        /// <returns>
        /// A result for the operation.
        /// </returns>
        public ILyncResult SetCallForwardingDelegation(LyncCallForwardingParameter param, string state)
        {
            return new DelegationPage(param);
        }

        /// <summary>
        /// Errors the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>
        /// A result for the operation.
        /// </returns>
        public ILyncResult Error(string message)
        {
            return new ErrorPage(message);
        }
    }
}
